package com.simon.resourcestatistics.util;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import com.simon.resourcestatistics.model.Member;

import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

/**
 * POIUtil
 */
public class POIUtil {


	//导入会员信息
    public static List<Member> impoMembers(String path) throws IOException{
        List<Member> list=new ArrayList<Member>();
        //路径
        File file=new File(path);
        //获得文件的输入流
        FileInputStream stream=new FileInputStream(file);
        //多态 抛异常
        Workbook sheets=new XSSFWorkbook(stream);
        //获取一个工作表（sheet页），下标从0开始
        Sheet sheet= sheets.getSheetAt(0);
        for(int i=1;i<sheet.getLastRowNum();i++){
           
             //获取行值
             Row row =sheet.getRow(i);
             // 获取单元格 取值
                String name = row.getCell(0).getStringCellValue();
                String sex = row.getCell(1).getStringCellValue();
                String category = row.getCell(2).getStringCellValue();
                String card = row.getCell(3).getStringCellValue();
                String department = row.getCell(4).getStringCellValue();
                String profession = row.getCell(5).getStringCellValue();
                String grade = row.getCell(6).getStringCellValue();
                String phone = row.getCell(7).getStringCellValue();
     
              Member m=new Member();
              m.setCardNo(CardUtil.getCardNo());
              m.setCard(card);
              m.setCategory(category);
              m.setDepartment(department);
              m.setGrade(grade);
              m.setName(name);
              m.setPhone(phone);
              m.setProfession(profession);
              m.setSex(sex);

              list.add(m);
            }

            //关流
            sheets.close();
            stream.close();

        return list;

    }

}